package top.healthylife.gateway.platform.fh.api.api.gsdqygqcz;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import top.healthylife.gateway.core.service.ParentFace;
import top.healthylife.gateway.dto.annotation.ApiServiceExplain;
import top.healthylife.gateway.platform.fh.api.api.IUnifyHandler;
import top.healthylife.gateway.platform.fh.api.util.FhHttpUtil;
import top.healthylife.gateway.platform.fh.dto.gsdqygqcz.detailsquery.req.FhReqDetailsQueryPledgeDto;
import top.healthylife.gateway.platform.fh.dto.gsdqygqcz.detailsquery.res.FhResDetailsQueryPledgeDto;

/**
 * @author : GaoZeXi
 * @date 2021/11/1 11:17
 */
@Slf4j
@Service
@ApiServiceExplain(price = 20, apiName = "工商大企业股权出质数据高精版-详情查询", docUrl = "-", info = "工商大企业股权出质数据高精版-详情查询-数据类型:company_gqcz")
public class FhDetailsQueryPledgeApi implements ParentFace<FhReqDetailsQueryPledgeDto, FhResDetailsQueryPledgeDto>, IUnifyHandler {
    private static final String DOMAIN = "export";

    @Override
    public FhResDetailsQueryPledgeDto execute(FhReqDetailsQueryPledgeDto t) {
        t.checkDataType();
        String dataType = t.getDataType();
        String suffix = ObjectUtil.isEmpty(dataType) ? DOMAIN : DOMAIN + "/" + dataType;
        JSONObject jsonObject = FhHttpUtil.HttpRequest(t, suffix);
        if (jsonObject == null) {
            return new FhResDetailsQueryPledgeDto();
        }
        if (StrUtil.isBlank(t.getDataType())) {
            return fillAllFields(jsonObject, t, FhResDetailsQueryPledgeDto.class);
        } else {
            return fillFieldsByDataType(jsonObject, t, FhResDetailsQueryPledgeDto.class);
        }
    }
}
